package rhc.taskSchedule.dao;

import java.util.List;

import org.json.JSONObject;

public class Page<T> implements java.io.Serializable{
	
	private static final long serialVersionUID = 1L;
	
	/**每页显示多少条记录**/
	private Integer pageSize=10;
	/** 总的记录数**/
	private Long totalCount;
	/** 当前第几页**/
	private Integer pageCount;
	private Integer currentPage=1;
	/** 分页记录,存放一个List返回.**/
	private List<T> list;
	/** 排序字段,默认按照创建时间排列.*/
	private String order = "create_time";
	/** 排序顺序,默认按照升序排序.*/
	private String orderBy = "desc";
	//开始位置
	private Integer start=-1;
	//结束位置
	private Integer end=-1;
	
	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}


	public Long getTotalCount() {
		return totalCount == null?0:totalCount;
	}

	public void setTotalCount(Long totalCount) {
		this.totalCount = totalCount;
	}
	
	public Integer getPageCount(){
		return (int)(totalCount+pageSize-1)/pageSize;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(Integer currentPage) {
		this.currentPage=null==currentPage?1:currentPage;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	public String getOrder() {
		return order;
	}

	public void setOrder(String order) {
		this.order = order;
	}

	public String getOrderBy() {
		return orderBy;
	}

	public void setOrderBy(String orderBy) {
		this.orderBy = orderBy;
	}
	
	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public Integer getEnd() {
		return end;
	}

	public void setEnd(Integer end) {
		this.end = end;
	}

	public String toString(){
		JSONObject o=new JSONObject();
		try{
		o.put("page_size", pageSize);
		o.put("total_count", totalCount);
		o.put("page_count", pageCount);
		o.put("current_page", currentPage);
		o.put("list", list.toString());
		}catch(Exception e){}
		return o.toString();
	}
}
